a11y: Redo notebok page lifetime management
authorBenjamin Otte <otte@redhat.com>
Wed, 29 Jun 2011 12:42:16 +0000 (14:42 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 5 Jul 2011 20:08:55 +0000 (16:08 -0400)
It is now done by the GailNotebook. Previously it tried to do it itself.
Also, we now use GtkNotebook::page-removed to track the removal, as
opposed to child::parent-set.

gtk/a11y/gailnotebook.c
gtk/a11y/gailnotebookpage.c
gtk/a11y/gailnotebookpage.h

index 17fb6c7095e1535b8ae042d11f13b126fb1a99c4..9997547e01ec59fd2ac5b8f29758aa4300460513 100644 (file)
@@ -35,9 +35,6 @@ static void         gail_notebook_real_notify_gtk     (GObject           *obj,
 
 static AtkObject*   gail_notebook_ref_child           (AtkObject      *obj,
                                                        gint           i);
-static gint         gail_notebook_real_remove_gtk     (GtkContainer   *container,
-                                                       GtkWidget      *widget,
-                                                       gpointer       data);    
 static void         atk_selection_interface_init      (AtkSelectionIface *iface);
 static gboolean     gail_notebook_add_selection       (AtkSelection   *selection,
                                                        gint           i);
@@ -75,10 +72,8 @@ gail_notebook_class_init (GailNotebookClass *klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   AtkObjectClass  *class = ATK_OBJECT_CLASS (klass);
   GailWidgetClass *widget_class;
-  GailContainerClass *container_class;
 
   widget_class = (GailWidgetClass*)klass;
-  container_class = (GailContainerClass*)klass;
 
   gobject_class->finalize = gail_notebook_finalize;
 
@@ -91,7 +86,6 @@ gail_notebook_class_init (GailNotebookClass *klass)
    * as the implementation in GailContainer returns the correct
    * number of children.
    */
-  container_class->remove_gtk = gail_notebook_real_remove_gtk;
 }
 
 static void
@@ -150,6 +144,34 @@ gail_notebook_page_added (GtkNotebook *gtk_notebook,
   notebook->page_count++;
 }
 
+static void
+gail_notebook_page_removed (GtkNotebook *notebook,
+                            GtkWidget   *widget,
+                            guint        page_num,
+                            gpointer     data)    
+{
+  GailNotebook *gail_notebook;
+  AtkObject *obj;
+  gint index;
+
+  gail_notebook = GAIL_NOTEBOOK (gtk_widget_get_accessible (GTK_WIDGET (notebook)));
+  index = gail_notebook->remove_index;
+  gail_notebook->remove_index = -1;
+
+  obj = find_child_in_list (gail_notebook->page_cache, index);
+  g_return_if_fail (obj);
+  gail_notebook->page_cache = g_list_remove (gail_notebook->page_cache, obj);
+  gail_notebook->page_count -= 1;
+  reset_cache (gail_notebook, index);
+  g_signal_emit_by_name (gail_notebook,
+                         "children_changed::remove",
+                         page_num,
+                         obj,
+                         NULL);
+  gail_notebook_page_invalidate (GAIL_NOTEBOOK_PAGE (obj));
+  g_object_unref (obj);
+}
+
 static void
 gail_notebook_real_initialize (AtkObject *obj,
                                gpointer  data)
@@ -177,6 +199,10 @@ gail_notebook_real_initialize (AtkObject *obj,
                     "page-added",
                     G_CALLBACK (gail_notebook_page_added),
                     NULL);
+  g_signal_connect (gtk_notebook,
+                    "page-removed",
+                    G_CALLBACK (gail_notebook_page_removed),
+                    NULL);
   g_object_weak_ref (G_OBJECT(gtk_notebook),
                      (GWeakNotify) gail_notebook_destroyed,
                      obj);                     
@@ -501,33 +527,6 @@ gail_notebook_child_parent_set (GtkWidget *widget,
   gail_notebook->remove_index = GAIL_NOTEBOOK_PAGE (data)->index;
 }
 
-static gint
-gail_notebook_real_remove_gtk (GtkContainer *container,
-                               GtkWidget    *widget,
-                               gpointer      data)    
-{
-  GailNotebook *gail_notebook;
-  AtkObject *obj;
-  gint index;
-
-  g_return_val_if_fail (container != NULL, 1);
-  gail_notebook = GAIL_NOTEBOOK (gtk_widget_get_accessible (GTK_WIDGET (container)));
-  index = gail_notebook->remove_index;
-  gail_notebook->remove_index = -1;
-
-  obj = find_child_in_list (gail_notebook->page_cache, index);
-  g_return_val_if_fail (obj, 1);
-  gail_notebook->page_cache = g_list_remove (gail_notebook->page_cache, obj);
-  gail_notebook->page_count -= 1;
-  reset_cache (gail_notebook, index);
-  g_signal_emit_by_name (gail_notebook,
-                         "children_changed::remove",
-                          GAIL_NOTEBOOK_PAGE (obj)->index, 
-                          obj, NULL);
-  g_object_unref (obj);
-  return 1;
-}
-
 static gboolean
 gail_notebook_focus_cb (GtkWidget      *widget,
                         GtkDirectionType type)
index 1bf12da716dd16eed60c68ddbff35d52e9b4cc3e..13b3e569694fd5dc0d8aff1a1a4acaa1d93c6e19 100644 (file)
@@ -185,7 +185,6 @@ gail_notebook_page_new (GtkNotebook *notebook,
 
   page = GAIL_NOTEBOOK_PAGE (object);
   page->notebook = notebook;
-  g_object_add_weak_pointer (G_OBJECT (page->notebook), (gpointer *)&page->notebook);
   page->index = pagenum;
   widget_page = gtk_notebook_get_nth_page (notebook, pagenum);
   page->page = widget_page;
@@ -214,6 +213,18 @@ gail_notebook_page_new (GtkNotebook *notebook,
   return atk_object;
 }
 
+void
+gail_notebook_page_invalidate (GailNotebookPage *page)
+{
+  g_return_if_fail (GAIL_IS_NOTEBOOK_PAGE (page));
+
+  atk_object_notify_state_change (ATK_OBJECT (page),
+                                  ATK_STATE_DEFUNCT,
+                                  TRUE);
+  atk_object_set_parent (ATK_OBJECT (page), NULL);
+  page->notebook = NULL;
+}
+
 static void
 gail_notebook_page_label_map_gtk (GtkWidget *widget,
                                   gpointer data)
@@ -282,9 +293,6 @@ gail_notebook_page_finalize (GObject *object)
 {
   GailNotebookPage *page = GAIL_NOTEBOOK_PAGE (object);
 
-  if (page->notebook)
-    g_object_remove_weak_pointer (G_OBJECT (page->notebook), (gpointer *)&page->notebook);
-
   if (page->textutil)
     g_object_unref (page->textutil);
 
index a87e0722df4f1fcd7070a72cc20d754b7cc2993f..78aaca416404ea870362574df86f69bf63067fc4 100644 (file)
@@ -61,6 +61,8 @@ struct _GailNotebookPageClass
 
 AtkObject *gail_notebook_page_new(GtkNotebook *notebook, gint pagenum);
 
+void       gail_notebook_page_invalidate (GailNotebookPage *page);
+
 G_END_DECLS
 
 #endif /* __GAIL_NOTEBOOK_PAGE_H__ */